'''
Created on Nov 30, 2010

@author: oabalbin
'''

#import subprocess

def fixmateInformation(indexed_bam_file, use_mem, path_to_picard, temp_dir):
    '''
    '''
    picard_command=path_to_picard+'FixMateInformation.jar'
    use_temp_dir='-Djava.io.tmpdir='+temp_dir
    outfile=indexed_bam_file.replace('.bam','.fixMate.bam')
    maxinram=500000
    args = ['java','-Xmx'+str(use_mem)+'g', use_temp_dir,'-jar',picard_command,
            'I='+indexed_bam_file,'SO=coordinate', 'VALIDATION_STRINGENCY=SILENT',
            'O='+outfile,'MAX_RECORDS_IN_RAM',str(maxinram)
            ] 
    
    args= [a.replace(',',';') for a in args]
    command = ",".join(args).replace(',',' ').replace(';',',')

    return command, outfile


def markDuplicates(indexed_bam_file, use_mem, path_to_picard):
    '''
    '''
    picard_command=path_to_picard+'MarkDuplicates.jar'
    outfile=indexed_bam_file.replace('.bam','.markdup.bam')
    metrics_file=indexed_bam_file.replace('.bam','.duplicates.stats')
    
    args=['java','-Xmx'+str(use_mem)+'g',picard_command, 
          'I='+indexed_bam_file, 'O='+outfile, 'METRICS_FILE='+metrics_file,
          'ASSUME_SORTED=true','VALIDATION_STRINGENCY=SILENT'
          ]
    
    args= [a.replace(',',';') for a in args]
    command = ",".join(args).replace(',',' ').replace(';',',')

    return command, outfile
